package com.chenchao.method;

import java.util.function.Predicate;

/**
 * @encoding : UTF-8
 * @Time : 2020/12/4 17:07
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.method.Test07.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 *  Predicate接口
 * 打印姓名长度大于2；年龄大于33
 */
public class Test07 {
    public static void main(String[] args) {
        test01();
        System.out.println("=====================");
        test02();
    }
    public static void test01(){
        String[] strArray = {"林青霞,30", "柳岩,34", "张曼玉,35", "貂蝉,31", "王祖贤,33"};
        for (String s : strArray) {
            boolean b = printInfo(s.split(",")[0], Integer.parseInt(s.split(",")[1]),
                    str -> str.length() > 2,
                    i -> i > 33);
            if (b) {
                System.out.println(s);
            }
        }
    }
    public static void test02(){
        String[] strArray = {"林青霞,30", "柳岩,34", "张曼玉,35", "貂蝉,31", "王祖贤,33"};
        for (String s : strArray) {
            boolean b = printInfo2(s,
                    str-> str.split(",")[0].length()>2,
                    str-> Integer.parseInt(str.split(",")[1])>33);
            if (b) {
                System.out.println(s);
            }
        }
    }
    public static boolean printInfo2(String str,
                                    Predicate<String> pre1, Predicate<String > pre2) {
        return pre1.and(pre2).test(str);
    }
    public static boolean printInfo(String str, Integer integer,
                                    Predicate<String> pre1, Predicate<Integer> pre2) {
        return pre1.test(str) && pre2.test(integer);
    }
}
